package com.yocard.yxyd.ui.fragment.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.yocard.yxyd.utils.util.ToastUtils;
import com.yocard.yxyd.base.AppContext;
import com.yocard.yxyd.base.BasePresenter;
import com.yocard.yxyd.base.BaseView;
import com.yocard.yxyd.di.component.DaggerFragmentComponent;
import com.yocard.yxyd.di.component.FragmentComponent;
import com.yocard.yxyd.di.module.FragmentModule;

import javax.inject.Inject;

/**
 * Created on 2018/12/14.
 */
public abstract class BaseLazyFragment<T extends BasePresenter> extends LazyLoadFragment implements BaseView {
    @Inject
    protected T mPresenter;

    protected FragmentComponent getFragmentComponent() {
        return DaggerFragmentComponent.builder()
                .appComponent(AppContext.getAppComponent())
                .fragmentModule(getFragmentModule())
                .build();
    }

    protected FragmentModule getFragmentModule() {
        return new FragmentModule(this);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        initInject();
        mPresenter.attachView(this);
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        if (mPresenter != null) mPresenter.detachView();
        super.onDestroyView();
    }

    @Override
    public void showErrorMsg(String msg) {
        ToastUtils.showLong(msg);
    }

    protected abstract void initInject();

    public void showLoadingDialog(String msg) {
    }

    public void dismisDialog() {

    }
}
